package com.ruoyi.vplat.service.impl;

import java.util.List;
import java.util.Map;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.vplat.dao.VplatGatewayDao;
import com.ruoyi.vplat.domain.VplatGateway;
import com.ruoyi.vplat.service.IVplatGatewayService;

/**
 * 网关Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-19
 */
@Service
public class VplatGatewayServiceImpl implements IVplatGatewayService 
{
    @Autowired
    private VplatGatewayDao vplatGatewayDao;

    /**
     * 查询网关
     * 
     * @param id 网关主键
     * @return 网关
     */
    @Override
    public VplatGateway selectById(String id)
    {
        return vplatGatewayDao.selectById(id);
    }

    /**
     * 查询网关列表
     * 
     * @param vplatGateway 网关
     * @return 网关
     * @throws Exception
     */
    @Override
    public List<Map<String, Object>> queryList(Map<String, Object> param) throws Exception
    {
        List<Map<String, Object>> list = vplatGatewayDao.queryList(param);
        //BeanUtils.caseFormat(list); 在Mybatis拦截器插件中统一处理
		return list;
    }
    
    /**
     * 查询网关列表
     * 
     * @param vplatGateway 网关
     * @return 网关
     */
    @Override
    public List<VplatGateway> selectList(VplatGateway vplatGateway)
    {
        return vplatGatewayDao.selectList(vplatGateway);
    }

    /**
     * 新增网关
     * 
     * @param vplatGateway 网关
     * @return 结果
     */
    @Override
    public int insert(VplatGateway vplatGateway)
    {
        //vplatGateway.setCreateTime(DateUtils.getNowDate());
        return vplatGatewayDao.insert(vplatGateway);
    }

    /**
     * 修改网关
     * 
     * @param vplatGateway 网关
     * @return 结果
     */
    @Override
    public int update(VplatGateway vplatGateway)
    {
        //vplatGateway.setUpdateTime(DateUtils.getNowDate());
        return vplatGatewayDao.update(vplatGateway);
    }

    /**
     * 批量删除网关
     * 
     * @param ids 需要删除的网关主键
     * @return 结果
     */
    @Override
    public int deleteByIds(String[] ids)
    {
        return vplatGatewayDao.deleteByIds(ids);
    }

    /**
     * 删除网关信息
     * 
     * @param id 网关主键
     * @return 结果
     */
    @Override
    public int deleteById(String id)
    {
        return vplatGatewayDao.deleteById(id);
    }
    @Override
    public VplatGateway selectByName(String name) {
    	return vplatGatewayDao.selectByName(name);
    }
    @Override
    public VplatGateway down(String username) {
    	return chnageOnline(username, 0);
    }

	/**
	 * @param username
	 * @param online
	 * @return
	 */
	private VplatGateway chnageOnline(String username, int online) {
		VplatGateway gateway = selectById(username);
		if (gateway != null) {
			gateway.setOnline(online);
			update(gateway);
		}
		return gateway;
	}
    @Override
    public VplatGateway up(String username) {
    	return chnageOnline(username, 1);
    }
    @Override
    public int downAll() {
    	return vplatGatewayDao.downAll();
    }
}
